package componentes;

import java.awt.Color;

import com.uqbar.metalGear.MGSScene;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.FilledArc;
import com.uqbar.vainilla.colissions.CollisionDetector;

public class Vision extends GameComponent<MGSScene>{
	
	private Soldado soldado;
	private Color color;
	private int radius;
	private double startAngle;
	private double arcAngle;
	
	public Vision(int x, int y, Color color, int radius, double startAngle, double arcAngle, Soldado soldado){
		super(new FilledArc(color, radius, startAngle, arcAngle), x, y);
		this.soldado = soldado;
		
		this.setZ(3);
		this.color = color;
		this.radius = radius;
		this.startAngle = startAngle;
		this.arcAngle = arcAngle;
	}

	public void update(DeltaState deltaState) {
		
		this.setX(this.getSoldado().getX() - this.getAppearance().getWidth()/2 + this.getSoldado().getAppearance().getWidth()/2 );
		this.setY(this.getSoldado().getY() - this.getAppearance().getHeight()/2 + this.getSoldado().getAppearance().getHeight()/2 );
		
		if(this.getSoldado().getCambioDir()){

			this.setAppearance(this.getSoldado().getDireccion().visionCorrespondiente(this.getSoldado(), this));
			this.getSoldado().setCambioDir(false);
		}
		
		super.update(deltaState);
	}
	
	public Boolean estaEnPosibleColision(Personaje p){
		
		return CollisionDetector.INSTANCE.collidesCircleAgainstRect
				(this.getX(), this.getY(), this.getRadius(),
				p.getX(), p.getY(), p.getAppearance().getWidth(), p.getAppearance().getHeight());
	}
	
	public Boolean detectaPJ(Personaje p){
		
		return this.getSoldado().getDireccion().colisionaConPJ(this, p, p.getScene());	
	}
	
	//accesos
	
	public Soldado getSoldado() {
		return soldado;
	}

	public void setSoldado(Soldado soldado) {
		this.soldado = soldado;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public int getRadius() {
		return radius;
	}

	public void setRadius(int radius) {
		this.radius = radius;
	}

	public double getStartAngle() {
		return startAngle;
	}

	public void setStartAngle(double startAngle) {
		this.startAngle = startAngle;
	}

	public double getArcAngle() {
		return arcAngle;
	}

	public void setArcAngle(double arcAngle) {
		this.arcAngle = arcAngle;
	}
	
}
